Introduction to UrbanScape

Welcome to this tutorial on running simulations with the UrbanScape Agent-based Model. By the end of this tutorial, you will be able to play with the different conditions that are encoded within the UrbanScape module and run in silico experiments to test and visualize the results of your hypotheses!

Functions

Before we dive into UrbanScape, it'll be useful to know about functions. They are much like the functions in math. Some function f takes an input x and gives an output y. In programming, a function takes one or more arguments, and returns an output.

But first, let me give you some problems to solve :)


In [ ]:
# assign 5 + 3 to the variable x

In [ ]:
# assign 1000 + 2 to the variable y

In [ ]:
# assign 1.041 + (-2.512) to the variable z

As a toy example, let's define a function that can perform addition so you don't have to type in the numbers and assign a variable to it each time. This is how you define a function in python:

def some_task(argument1, ...):
    result = do_something
    return result

In [2]:
# define your own addition function below

This seems pretty trivial right now, but to drive home the point of how awesome functions are, what if you wanted to perform this task over and over again? You can now use your addition function, or 'call' your addition function whenever you want.


In [ ]:
# apply the addition function to adding elements in two lists by index

Importing Modules

Now we have all the tools we need to start running simulations. First, we want to import the UrbanScape module so that we can start running simulation experiments


In [2]:
# Type in and run importing script here
import UrbanScape.urbanscape as us

Creating your first UrbanScape

Now let's build our first UrbanScape. In the simplest case, UrbanScape takes three arguments: size, rent, and create_rule. We'll get into create rules later but for now don't worry about it. Create an UrbanScape of size 3, rent (i.e. rent ceiling) as 100.


In [3]:
# set a variable size to 3
size = 3

# set a rent variable to 100
rent = 100

# create your first UrbanScape!
my_first_urbanscape = us.UrbanScape(3, 100)

In [5]:
#print out the rent distribution of your first urbanscape
print my_first_urbanscape.rent


[[ 100.  100.  100.]
 [ 100.  100.  100.]
 [ 100.  100.  100.]]

In [6]:
#print out the income distribution of your first urbanscape
print my_first_urbanscape.income


[[ 400.  400.  400.]
 [ 400.  400.  400.]
 [ 400.  400.  400.]]

When you create an UrbanScape, you can also randomize the rent distribution. You can do this by setting an optional argument randomize as true. Create an UrbanScape with the same parameter values as above that randomizes the starting rent distribution.


In [7]:
# Create your randomized UrbanScape here, the print the rent and income distribution
my_urbanscape = us.UrbanScape(3, 100, randomize = True)
print my_urbanscape.rent
print my_urbanscape.income


[[ 100.          100.          100.        ]
 [  83.52713723  100.           84.6058645 ]
 [  83.91424671  100.          100.        ]]
[[ 328.80779233  400.          369.84750286]
 [ 400.          400.          343.8540304 ]
 [ 338.27077673  382.48406353  400.        ]]

In [8]:
# Create a bigger UrbanScape with a higher rent ceiling.
# Set size to 20 and rent to 100000, randomize = True
my_big_urbanscape = us.UrbanScape(20, 100000, randomize = True)

#print the rent and distribution
print my_big_urbanscape.rent
print my_big_urbanscape.income


[[ 100000.           94436.72819033  100000.           92199.44882049
    80663.56401449  100000.           92661.8049589   100000.
    83173.49958314   83752.258847     86250.60608601  100000.          100000.
   100000.          100000.           88470.81757682   88951.81029368
    84349.88870353  100000.          100000.        ]
 [  86047.03335399  100000.          100000.           90422.04276288
   100000.          100000.          100000.          100000.          100000.
    79034.34057068  100000.           77230.33773876  100000.          100000.
   100000.          100000.           95750.65965638  100000.
    79867.87504802   84213.26796758]
 [  88386.61597481   84540.887604    100000.           82716.36102834
    82612.2872098    92890.6294659   100000.           96216.5494388
   100000.           96109.98397163  100000.          100000.          100000.
    96602.40242316   87458.24117897  100000.           81100.89462906
    77691.02360539   90031.49968525   91642.06461755]
 [  98406.2507329    76861.76166699   77944.18477005  100000.
    85657.83077038   81353.84116024   79916.28916923  100000.
    86910.76707504  100000.          100000.           76646.54545758
   100000.          100000.           98946.52754985  100000.          100000.
    93299.9757675   100000.          100000.        ]
 [  97969.08339343  100000.          100000.          100000.          100000.
   100000.          100000.          100000.           81973.14961823
   100000.          100000.           80255.37848065   93155.58529723
   100000.          100000.          100000.           76770.30077045
    99843.10492205   92599.03110071  100000.        ]
 [ 100000.           87099.79537126  100000.           75421.30350941
   100000.          100000.          100000.           85822.55727453
    93278.11241303  100000.          100000.           99531.6509274
    89291.32977581  100000.           76642.07921529   99447.21176663
    83515.38431783   82373.51598695  100000.           98045.58217118]
 [ 100000.          100000.           76614.56120536  100000.          100000.
   100000.          100000.           83593.00779752   96647.87956618
    93147.7193157   100000.          100000.          100000.          100000.
   100000.          100000.           88621.03518199   75165.63532869
   100000.           79015.91885879]
 [ 100000.           82896.84468769   97215.57634246  100000.
    80091.25671652   85551.70226656   97201.33887634  100000.          100000.
    95861.5810337   100000.          100000.          100000.          100000.
    75240.66662913  100000.          100000.           94853.75582986
    98108.76521794  100000.        ]
 [ 100000.           78248.92218584   77513.53804473   89876.452236
   100000.           99723.24601338  100000.           94776.07838869
   100000.          100000.           90634.15137169  100000.
    79996.11317355   82816.00420564   82476.01885546  100000.
    83647.57216336   94949.03492773  100000.          100000.        ]
 [ 100000.          100000.          100000.          100000.
    78720.55648812   79389.10070764  100000.           92924.42279306
    76208.80064418   78661.33730897   82500.49794745   99087.74575412
    77523.47405248  100000.          100000.          100000.          100000.
   100000.           90054.01011945   78591.79862674]
 [ 100000.          100000.           75240.22770011   79946.56923024
   100000.           88944.01566844   84168.38059229   84304.28175231
   100000.           97436.48469741  100000.           77009.5999644
   100000.           90218.83255004  100000.           85134.07485772
    92268.98481837  100000.           85492.98940809   78920.58628657]
 [  87499.02353423  100000.          100000.           90592.43462775
    93538.37029897   77737.44477665  100000.           91170.34861749
    84224.53248258  100000.           88824.9462219    91516.88933455
    92138.82572248   83236.55826826  100000.          100000.
    97575.75291255   97051.75670354   87430.41294251   78983.71478416]
 [ 100000.          100000.          100000.           76038.9837868
   100000.          100000.           80834.46295433   86674.35885521
   100000.           78851.71097939  100000.          100000.          100000.
    84236.79180297  100000.           96128.79347432   80726.27813296
   100000.           92921.17074528   75072.35160692]
 [ 100000.          100000.          100000.          100000.
    83474.34694631   85559.0568084    87040.31159797   93542.18690007
    76845.42288013   95651.64611003   79566.02988024  100000.
    80737.79253615  100000.          100000.           77069.61353203
   100000.          100000.          100000.          100000.        ]
 [  89349.59520284  100000.           95299.81040309   95584.28058314
    76117.34263417  100000.           76745.2879427   100000.          100000.
   100000.           92198.54896077   97628.94389027   91719.59648055
   100000.          100000.           84048.33423747  100000.          100000.
   100000.           96658.79540355]
 [  89908.00992655  100000.          100000.          100000.
    98395.05971408  100000.           81493.79635812  100000.
    78339.96856956  100000.          100000.           93494.48975121
    85069.64782669   93987.49833936   80578.18377158  100000.
    94196.40967988   76389.42697502  100000.          100000.        ]
 [  83376.67362223   87955.39293411  100000.           86697.48400426
   100000.           93309.4516096    84733.80615616  100000.
    91149.88112943   82853.90775781   81575.88207597   83858.35819869
   100000.           89457.38562941   80377.64294747   99425.68010852
   100000.          100000.          100000.           87791.57823967]
 [  77983.24771124   90683.19699779  100000.          100000.          100000.
   100000.           80572.32024731   79230.5542402    94064.14909397
   100000.          100000.           93050.69135455   96474.58794123
   100000.          100000.          100000.           88913.61055032
   100000.           83719.68231169  100000.        ]
 [ 100000.          100000.          100000.           83732.16776256
    90616.3793509    77535.80856421  100000.           86909.96531699
   100000.           90634.03504694  100000.           95802.34949879
    98257.49921021   85201.98109075   91543.21631246   91719.41146629
   100000.           87486.59963376   87271.66732488   82023.79853088]
 [  88466.86443995  100000.           98664.17342368  100000.          100000.
    82418.97200436   87079.89919065   97205.42496377  100000.          100000.
   100000.           93761.69826035  100000.           91013.44280874
   100000.          100000.           85694.74109566  100000.          100000.
   100000.        ]]

In [ ]:
#build a bigger UrbanScape >> print us.rent
#play with distribution argument >> print us.rent
#%pylab inline and use plot_urbanscape to visualize it
#add agents manually >> plot it
#introduce the create rule >> visualize with animation
#run_experiments function >> plot it
#run_batch experiments function >> plot it